//
//  PywCheckSmsCodeAndBindApi.m
//  PywSdk
//
//  Created by Jade on 16/8/31.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywCheckSmsCodeAndBindApi.h"
#import "AIFCheckSmsCodeAndBindManager.h"
#import "PropertyListReformer.h"
#import "PywMBProgressHUD+Pyw.h"
@interface PywCheckSmsCodeAndBindApi()<ETAPIManagerCallBackDelegate>

@end
@implementation PywCheckSmsCodeAndBindApi

- (void)requestCheckSmsCodeAndBindWithParams:(MutableDictionary *)params
                                     success:(Successd)success
                                        fail:(Failure)fail
{
    self.successd = success;
    self.failure = fail;
    [PywMBProgressHUD showMessage:@"正在绑定..."];
    NSString *passport = [params objectForKey:@"passport"];
    NSString *smsType = [params objectForKey:@"smsType"];
    NSString *smsCode = [params objectForKey:@"smsCode"];
    AIFCheckSmsCodeAndBindManager *manager = [AIFCheckSmsCodeAndBindManager manager];
    manager.delegate = self;
    manager.passport = passport;
    manager.smscode = smsCode;
    manager.smstype = smsType;
    [manager loadData];
}

- (void)managerCallAPIDidSuccess:(ETApiBaseManager *)manager
{
    [PywMBProgressHUD hideHUD];
    PropertyListReformer *reformer = [[PropertyListReformer alloc] init];
    NSDictionary *dict = [manager fetchDataWithReformer:reformer];
    NSInteger ack = [[dict objectForKey:@"ack"] integerValue];
    if (ack == 200) {
        NSString *type = [[dict objectForKey:@"data"] objectForKey:@"type"];
        if (self.successd) {
            self.successd(type,nil);
        }
    }else {
        NSString *msg = [dict objectForKey:@"msg"];
        [PywMBProgressHUD showError:msg];
        if (self.failure) {
            self.failure([self errorWithCode:ack]);
        }
    }
    
    
}
- (void)managerCallApiDidFailed:(ETApiBaseManager *)manager
{
    [PywMBProgressHUD showError:@"绑定失败，请重新绑定!"];
    if (self.failure) {
        self.failure([self errorWithCode:0]);
    }
}
@end
